package com.chezhujie.www.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

/**
 * 
 * @author 汤伟杰
 *
 */
public class UUIDUtils {
	private static String digits(long val, int digits) {
	    long hi = 1L << (digits * 4);  
	    return Numbers.toString(hi | (val & (hi - 1)), Numbers.MAX_RADIX)  
	            .substring(1);  
	}  
	public static String getUUID() {
        UUID uuid = UUID.randomUUID();
        StringBuilder sb = new StringBuilder();
        sb.append(digits(uuid.getMostSignificantBits() >> 32, 8));
        sb.append(digits(uuid.getMostSignificantBits() >> 16, 4));
        sb.append(digits(uuid.getMostSignificantBits(), 4));
        sb.append(digits(uuid.getLeastSignificantBits() >> 48, 4));
        sb.append(digits(uuid.getLeastSignificantBits(), 12));
        return sb.toString();
    }
	public static String getDateUUID() {
        UUID uuid = UUID.randomUUID();
        StringBuilder sb = new StringBuilder();
        sb.append(digits(uuid.getMostSignificantBits() >> 32, 8));
        sb.append(digits(uuid.getMostSignificantBits() >> 16, 4));
        sb.append(digits(uuid.getMostSignificantBits(), 4));
        sb.append(digits(uuid.getLeastSignificantBits() >> 48, 4));
        sb.append(digits(uuid.getLeastSignificantBits(), 12));
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyMMddHHmmss");
        String dd=simpleDateFormat.format(new Date());
        return dd+sb.substring(0,7);
    }
	public static void main(String[] args) {
		for(int i=0;i<500;i++){
			System.out.println(UUIDUtils.getUUID());
		}
	}
}
